﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace DevelopTools.UI
{
    /// <summary>
    /// 打字效果
    /// </summary>
    public class TypeWritter : MonoBehaviour
    {
        Text thisText;
        public string texts;
        float timer;
        public int charsPerSecond = 1;
        // Use this for initialization
        void Start()
        {
            thisText = GetComponent<Text>();
            //texts = thisText.text;
            thisText.text = "";
            isNotFirst = true;
            //        Debug.Log("Start  ");
        }
        bool isNotFirst;
        // Update is called once per frame
        void Update()
        {
            if (texts.Length >= (int)(charsPerSecond * timer))
            {
                thisText.text = texts.Substring(0, (int)(charsPerSecond * timer));
                timer += Time.deltaTime;
            }
        }

        void OnEnable()
        {
            thisText = GetComponent<Text>();
            thisText.text = "";
            timer = 0;
            //Debug.Log("OnEnable  ");

        }
    }
}